<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <title>CometD timesync demo</title>
    <script type="text/javascript" src="../../dojo/dojo.js"></script>
    <script type="text/javascript">
        dojo.registerModulePath("org", "../org");
        dojo.require("dojox.cometd");
        dojo.require("dojox.cometd.timesync");

        dojox.cometd.init(location.href.replace(/\/dojo-examples\/.*$/, '') + "/cometd");
        dojox.cometd.subscribe("/chat/demo", function()
        {
        });

        var tick = function()
        {
            var now = dojox.cometd.timesync.getServerDate();
            dojo.byId("time").innerHTML = now.toUTCString();
            dojo.byId("offset").innerHTML = dojox.cometd.timesync.getTimeOffset() + "  from samples " + dojox.cometd.timesync.getTimeOffsetSamples().join();
            now = now.getTime();
            var next = "" + (1 + now / 1000);
            next = parseInt(next.split('.')[0]) * 1000 + 10;
            dojox.cometd.timesync.setTimeout(tick, next);
        };

        setTimeout(tick, 1000);
        dojo.addOnUnload(dojox.cometd, "disconnect");
    </script>
</head>
<body>

<h1>TimeSync test</h1>
<a href="../..">Main Demo index</a><br/>

<p>
    This test uses the timesync extension to calculate a timeoffset with the server.
    The time displayed below is the server time and should be the same for all clients
    no matter what their local clocks are set to.
</p>

<p>The accuracy should improve as each connect response is received. If the client and
    server are on the same machine, then the algorithm will likely detect good accuracy and
    not send any samples.
</p>

<div id="time"></div>
<br/>
offset=<span id="offset"></span>
</body>
</html>
